<template><div><h2 id="安装" tabindex="-1"><a class="header-anchor" href="#安装"><span>安装</span></a></h2>
<p>Dcat Admin 中文文档 /</p>
<h2 id="安装-1" tabindex="-1"><a class="header-anchor" href="#安装-1"><span>安装</span></a></h2>
<h2 id="环境" tabindex="-1"><a class="header-anchor" href="#环境"><span>环境</span></a></h2>
<ul>
<li>PHP &gt;= <code v-pre>7.1</code></li>
<li>Laravel <code v-pre>5.5.0</code> ~ <code v-pre>9.*</code></li>
<li>Fileinfo PHP Extension</li>
</ul>
<h2 id="开始安装" tabindex="-1"><a class="header-anchor" href="#开始安装"><span>开始安装</span></a></h2>
<p>首先需要安装<code v-pre>laravel</code>框架，如已安装可以跳过此步骤。如果您是第一次使用<code v-pre>laravel</code>，请务必先阅读文档 <a href="https://learnku.com/docs/laravel/9.x/installation/12200" target="_blank" rel="noopener noreferrer">安装《Laravel 9 中文文档》</a> ！</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token function">composer</span> create-project --prefer-dist laravel/laravel 项目名称 <span class="token number">9</span>.*</span>
<span class="line"><span class="token comment"># 或</span></span>
<span class="line"><span class="token function">composer</span> create-project --prefer-dist laravel/laravel 项目名称</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>安装完<code v-pre>laravel</code>之后需要修改<code v-pre>.env</code>文件，设置数据库连接设置正确</p>
<div class="language-dotenv line-numbers-mode" data-highlighter="prismjs" data-ext="dotenv" data-title="dotenv"><pre v-pre class="language-dotenv"><code><span class="line">DB_CONNECTION=mysql</span>
<span class="line">DB_HOST=127.0.0.1</span>
<span class="line">DB_PORT=3306</span>
<span class="line">DB_DATABASE=dcat-admin</span>
<span class="line">DB_USERNAME=root</span>
<span class="line">DB_PASSWORD=</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>安装<code v-pre>dcat-admin</code></p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token builtin class-name">cd</span> <span class="token punctuation">{</span>项目名称<span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line"><span class="token function">composer</span> require dcat/laravel-admin:<span class="token string">"2.*"</span> <span class="token parameter variable">-vvv</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><blockquote>
<p>如果上一步出现报错，则更改<code v-pre>composer.json</code>的参数<code v-pre>minimum-stability</code>的值为<code v-pre>dev</code>。</p>
</blockquote>
<p>然后运行下面的命令来发布资源：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line">php artisan admin<span class="token punctuation">:</span>publish</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>在该命令会生成配置文件<code v-pre>config/admin.php</code>，可以在里面修改安装的地址、数据库连接、以及表名，建议都是用默认配置不修改。</p>
<p>然后运行下面的命令完成安装：</p>
<blockquote>
<p>{tip} 执行这一步命令可能会报以下错误<code v-pre>Specified key was too long ... 767 bytes</code>，如果出现这个报错，请在<code v-pre>app/Providers/AppServiceProvider.php</code>文件的<code v-pre>boot</code>方法中加上代码<code v-pre>\Schema::defaultStringLength(191);</code>，然后删除掉数据库中的所有数据表，再重新运行一遍<code v-pre>php artisan admin:install</code>命令即可。</p>
</blockquote>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line">php artisan admin<span class="token punctuation">:</span>install</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>上述步骤操作完成之后就可以配置<code v-pre>web</code>服务了，<strong>注意需要把<code v-pre>web</code>目录指向<code v-pre>public</code>目录</strong>！如果用的是<code v-pre>nginx</code>，还需要在配置中加上伪静态配置</p>
<div class="language-dotenv line-numbers-mode" data-highlighter="prismjs" data-ext="dotenv" data-title="dotenv"><pre v-pre class="language-dotenv"><code><span class="line">location / {</span>
<span class="line">    try_files $uri $uri/ /index.php?$query_string;</span>
<span class="line">}</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>启动服务后，在浏览器打开 <code v-pre>http://localhost/admin</code>，使用用户名 <code v-pre>admin</code> 和密码 <code v-pre>admin</code>登陆。</p>
<h2 id="生成的文件" tabindex="-1"><a class="header-anchor" href="#生成的文件"><span>生成的文件</span></a></h2>
<p>安装完成之后,会在项目目录中生成以下的文件:</p>
<h3 id="配置文件" tabindex="-1"><a class="header-anchor" href="#配置文件"><span>配置文件</span></a></h3>
<p>安装完成之后，<code v-pre>dcat-admin</code>所有的配置都在<code v-pre>config/admin.php</code>文件中。</p>
<h3 id="后台项目文件" tabindex="-1"><a class="header-anchor" href="#后台项目文件"><span>后台项目文件</span></a></h3>
<p>安装完成之后，后台的安装目录为<code v-pre>app/Admin</code>，之后大部分的后台开发编码工作都是在这个目录下进行。</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line">app<span class="token operator">/</span>Admin</span>
<span class="line">├── Controllers</span>
<span class="line">│   ├── AuthController<span class="token operator">.</span>php</span>
<span class="line">│   └── HomeController<span class="token operator">.</span>php</span>
<span class="line">├── Metrics</span>
<span class="line">│   └── Examples</span>
<span class="line">│       ├── NewDevices<span class="token operator">.</span>php</span>
<span class="line">│       ├── NewUsers<span class="token operator">.</span>php</span>
<span class="line">│       ├── ProductOrders<span class="token operator">.</span>php</span>
<span class="line">│       ├── Sessions<span class="token operator">.</span>php</span>
<span class="line">│       ├── Tickets<span class="token operator">.</span>php</span>
<span class="line">│       └── TotalUsers<span class="token operator">.</span>php</span>
<span class="line">├── bootstrap<span class="token operator">.</span>php</span>
<span class="line">└── routes<span class="token operator">.</span>php</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><ol>
<li><code v-pre>app/Admin/routes.php</code>文件用来配置后台路由。</li>
<li><code v-pre>app/Admin/bootstrap.php</code> 是<code v-pre>dcat-admin</code>的启动文件, 使用方法请参考文件里面的注释.</li>
<li><code v-pre>app/Admin/Controllers</code>目录用来存放后台控制器文件，该目录下的<code v-pre>HomeController.php</code>文件是后台首页的显示控制器，<code v-pre>AuthController.php</code>为后台管理员登录鉴权控制器。</li>
<li><code v-pre>app/Admin/Metrics/Examples</code>里面存放的是<code v-pre>数据统计卡片(Metric Card)</code>的示例代码.</li>
</ol>
<h3 id="静态文件" tabindex="-1"><a class="header-anchor" href="#静态文件"><span>静态文件</span></a></h3>
<p>后台所需的前端静态文件在<code v-pre>/public/vendor/dcat-admin</code>目录下。</p>
<h3 id="数据表迁移文件" tabindex="-1"><a class="header-anchor" href="#数据表迁移文件"><span>数据表迁移文件</span></a></h3>
<p>对应的数据表迁移文件在<code v-pre>/database/migrations</code>目录下。</p>
<h3 id="语言包" tabindex="-1"><a class="header-anchor" href="#语言包"><span>语言包</span></a></h3>
<p>语言包文件在<code v-pre>/resources/lang</code>目录下。</p>
</div></template>


